//
// In order to convert some functionality to Visual C#, the Java Language Conversion Assistant
// creates "support classes" that duplicate the original functionality.  
//
// Support classes replicate the functionality of the original code, but in some cases they are 
// substantially different architecturally. Although every effort is made to preserve the 
// original architecture of the application in the converted project, the user should be aware that 
// the primary goal of these support classes is to replicate functionality, and that at times 
// the architecture of the resulting solution may differ somewhat.
//

using System;
using Microsoft.Pex.Framework;

namespace StackAr
{

    /// <summary>
    /// Contains conversion support elements such as classes, interfaces and static methods.
    /// </summary>
    public class SupportClass
    {
        /// <summary>
        /// This class manages array operations.
        /// </summary>
        public class ArraySupport
        {
            /// <summary>
            /// Compares the entire members of one array whith the other one.
            /// </summary>
            /// <param name="array1">The array to be compared.</param>
            /// <param name="array2">The array to be compared with.</param>
            /// <returns>True if both arrays are equals otherwise it returns false.</returns>
            /// <remarks>Two arrays are equal if they contains the same elements in the same order.</remarks>
            public static bool Equals(System.Array array1, System.Array array2)
            {
                bool result = false;
                if ((array1 == null) && (array2 == null))
                    result = true;
                else if ((array1 != null) && (array2 != null))
                {
                    if (array1.Length == array2.Length)
                    {
                        int length = array1.Length;
                        result = true;
                        for (int index = 0; index < length; index++)
                        {
                            if (!(array1.GetValue(index).Equals(array2.GetValue(index))))
                            {
                                result = false;
                                break;
                            }
                        }
                    }
                }
                return result;
            }

            /// <summary>
            /// Fills the array with an specific value from an specific index to an specific index.
            /// </summary>
            /// <param name="array">The array to be filled.</param>
            /// <param name="fromindex">The first index to be filled.</param>
            /// <param name="toindex">The last index to be filled.</param>
            /// <param name="val">The value to fill the array with.</param>
            public static void Fill(System.Array array, System.Int32 fromindex, System.Int32 toindex, System.Object val)
            {
                System.Object Temp_Object = val;
                System.Type elementtype = array.GetType().GetElementType();
                if (val == null)
                    Temp_Object = null;
                else if (elementtype != val.GetType())
                    Temp_Object = System.Convert.ChangeType(val, elementtype);
                if (fromindex > toindex)
                    throw (new System.ArgumentException());
                if ((fromindex < 0) || ((System.Array)array).Length < toindex)
                    throw (new System.IndexOutOfRangeException());

                for (int index = (fromindex > 0) ? fromindex-- : fromindex; index < toindex; index++)
                    //for (
                    //    int index = PexSymbolicValue.Internal.LoopVar("$index", (fromindex > 0) ? fromindex-- : fromindex);
                    //    PexSymbolicValue.Ignore(index < toindex);
                    //    index = PexSymbolicValue.Internal.LoopVar("$index", index + 1))
                    array.SetValue(Temp_Object, index);
            }

            /// <summary>
            /// Fills the array with an specific value.
            /// </summary>
            /// <param name="array">The array to be filled.</param>
            /// <param name="val">The value to fill the array with.</param>
            public static void Fill(System.Array array, System.Object val)
            {
                Fill(array, 0, array.Length, val);
            }
        }


        /*******************************/
        //Provides access to a static System.Random class instance
        static public System.Random Random = new System.Random();

    }
}